package CtrlLayer;
import ModelLayer.*;
import DBLayer.*;

import java.util.ArrayList;

/**
 * CtrlSupplier.java
 * @author Brian Lassen
 * @version 20. Marts 2012
 */
public class CtrlSupplier {
	
	public CtrlSupplier(){}
	
	public static ArrayList<Supplier> findAllSupplier()
    {
      IFDBSupplier dbSupplier = new DBSupplier();
      ArrayList<Supplier> allSupplier = new ArrayList<Supplier>();
      allSupplier = dbSupplier.getAllSupplier(false);
      return allSupplier;
    }
	
	public static Supplier findById(int id)
    {
        IFDBSupplier dbSupplier = new DBSupplier();
        return dbSupplier.searchSupplierId(id, true);
    }

	public static Supplier findByName(String name)
    {
        IFDBSupplier dbSupplier = new DBSupplier();
        return dbSupplier.searchSupplierName(name, true);
    }
	
	public static Supplier findByPhone(int phone)
    {
        IFDBSupplier dbSupplier = new DBSupplier();
        return dbSupplier.searchSupplierPhone(phone, true);
    }
      
	public static int updateSupplier(int id, String name, String address, String country, String phone, String email)
	{
		IFDBSupplier  dbSupplier = new DBSupplier();
		Supplier mySupplier = new Supplier();
		mySupplier.setId(id);
		mySupplier.setName(name);
		mySupplier.setAddress(address);
		mySupplier.setCountry(country);
		mySupplier.setPhone(phone);
		mySupplier.setEmail(email);
		return dbSupplier.updateSupplier(mySupplier);
	}
      
	public static void insertNew(int id, String name, String address, String country, String phone, String email)
	{
		IFDBSupplier dbSupplier = new DBSupplier();
		Supplier supplierObj = new Supplier();
		supplierObj.setId(id);
		supplierObj.setName(name);
		supplierObj.setAddress(address);
		supplierObj.setCountry(country);
		supplierObj.setPhone(phone);
		supplierObj.setEmail(email);
		dbSupplier.insertSupplier(supplierObj);
	}
      
	public static void deleteCust(int id)
	{
		IFDBCustomer dbCust = new DBCustomer();
		dbCust.delete(id);
	}
}
